﻿using System.Linq;
using System.Web.Mvc;
using Omu.AwesomeDemo.Core.Model;
using Omu.AwesomeDemo.Core.Repository;

namespace Omu.AwesomeDemo.WebUI.Areas.Veggies.Controllers
{
    public class FruitAjaxRadioListController : Controller
    {
        private readonly IRepo<Fruit> r;

        public FruitAjaxRadioListController(IRepo<Fruit> r)
        {
            this.r = r;
        }

        public ActionResult GetItems(int? key)
        {
            var res = r.GetAll().Select(o => new SelectListItem { Text = o.Name, Value = o.Id.ToString(), Selected = (key == o.Id) });

            return Json(res);
        }
    }
}